package cn.wyu.web;

import cn.wyu.pojo.User;
import cn.wyu.service.userSericeimpl;
import cn.wyu.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        User user = new User();
        user.setLoginName(name);
        userService userService = new userSericeimpl();
        String checkName = userService.findUser(user);
        String checkpassword = userService.getPassword(user);

        System.out.println("在sevlet层打印");
        System.out.println(name + ":" + password);
        System.out.println(checkName + ":" + checkpassword);


        if (name == null || password == null) {
            System.out.println("name == null || password == null");
            response.getWriter().print(false);
        }
        else if (name.equals(checkName) && password.equals(checkpassword)) {
            System.out.println("checkName == name && checkpassword == password");
            response.getWriter().print(true);
        }
        else{
            System.out.println("else其它情况");
            response.getWriter().print(false);
        }
        System.out.println("responese之后");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
